/*
 * RoutePropertiesDialog.java
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.apps.rtemaster.gui.dialogs;

import org.fpdev.util.gui.GUIFactory;
import org.fpdev.core.transit.Route;
import org.fpdev.apps.rtemaster.RouteMaster;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import org.fpdev.apps.rtemaster.RMEvent;
import org.fpdev.apps.rtemaster.EventTypes;

public class RoutePropertiesDialog extends JDialog implements ActionListener {

  private RouteMaster av_;
  private JTextField name_;
  private JCheckBox showID_;
  private JButton newIDBtn_,  okBtn_,  cancelBtn_;
  private Route route_;

  public RoutePropertiesDialog(RouteMaster av, Route route) {
    super(av.getGUI(), "Route Properties", true);

    av_ = av;
    route_ = route;

    name_ = new JTextField(route.getName(), 20);
    showID_ = new JCheckBox("Display ID in Results", route.getShowID());

    newIDBtn_ = GUIFactory.newButton("New ID", 60, this);

    okBtn_ = new JButton("OK");
    okBtn_.addActionListener(this);
    cancelBtn_ = new JButton("Cancel");
    cancelBtn_.addActionListener(this);

    JPanel idRow = new JPanel();
    idRow.setLayout(new BoxLayout(idRow, BoxLayout.X_AXIS));
    idRow.add(new JLabel("Route ID: " + route_.getID()));
    idRow.add(Box.createHorizontalStrut(5));
    idRow.add(newIDBtn_);

    JPanel btnRow = new JPanel();
    btnRow.setLayout(new BoxLayout(btnRow, BoxLayout.X_AXIS));
    btnRow.add(okBtn_);
    btnRow.add(Box.createHorizontalStrut(5));
    btnRow.add(cancelBtn_);

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
    topPanel.add(idRow);
    topPanel.add(Box.createVerticalStrut(5));
    topPanel.add(name_);
    topPanel.add(Box.createVerticalStrut(5));
    topPanel.add(showID_);

    //rightRow.setAlignmentX(LEFT_ALIGNMENT);

    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));

    topPanel.setAlignmentX(CENTER_ALIGNMENT);
    mainPanel.add(topPanel);
    mainPanel.add(Box.createVerticalStrut(6));
    btnRow.setAlignmentX(CENTER_ALIGNMENT);
    mainPanel.add(btnRow);

    mainPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(mainPanel);

    this.pack();
    this.setLocation((av.getGUI().getWidth() / 2) - getWidth() / 2 + av.getGUI().getX(),
            (av.getGUI().getHeight() / 2) - getHeight() / 2 + av.getGUI().getY());

    setVisible(true);
  }

  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == newIDBtn_) {
      av_.fireEvent(new RMEvent(EventTypes.RTEPANEL_EDIT_RTE_ID));
      setVisible(false);
    }

    if (e.getSource() == okBtn_) {
      route_.setName(name_.getText());
      route_.setShowID(showID_.isSelected());
      setVisible(false);
    } else if (e.getSource() == cancelBtn_) {
      setVisible(false);
    }
  }
}

























